using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.EntityFrameworkCore;

namespace DealerPlatform.Core.Repository
{
    public static class LinqExtensions
    {
        public static async IAsyncEnumerable<TEntity> WhereAsync<TEntity>(this DbSet<TEntity> dbset, Func<TEntity, bool> func)
            where TEntity : class
        {
            var data = dbset.Where(func);
            foreach (var item in data)
            {
                yield return item;
            }
        }

        public static async Task<List<TEntity>> ToListAsync<TEntity>(this IAsyncEnumerable<TEntity> entities)
        {
            List<TEntity> list = new();
            await foreach(var item in entities)
            {
                list.Add(item);
            }
            return list;
        }
    }
}